package com.wanxi.education.mapper;

import com.wanxi.education.model.pojo.Role;
import com.wanxi.education.model.vo.role.RolePermissionVo;
import com.wanxi.education.model.vo.user.RoleVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Set;

/**
 * @Author: Kang
 * @Date: 2021/9/27 9:35
 * @Description: 权限
 * @Version: 1.0
 */
public interface RoleMapper {

    Set<RoleVO> findByUserId(@Param("userId") Long userId);

    List<RoleVO> findPage();

    int add(Role role);

    RoleVO findByRoleId(@Param("roleId") Long roleId);

    int updateById(Role role);

    int deleteByRoleId(@Param("roleId") Long roleId);


    //删除关于role_permission_relation中间表的数据
    @Delete("Delete from role_permission_relation where role_id=#{id}")
    void deleteRolePermissionById(Long id);

    @Insert({
            "<script>",
            "insert into role_permission_relation (role_id, permission_id,create_time,update_time) values ",
            // collection 和 value对应   item代表循环中List的这一项IpMap
            "<foreach collection='permissions' item='permissionId' index='index' separator=','>",
            "(#{id}, #{permissionId},NOW(),NOW())",
            "</foreach>",
            "</script>"
    })
    void updatePermissionsById(RolePermissionVo rolePermissionVo);

    @Select("select * from role")
    List<RoleVO> findAll();
}
